
       PROGRAM-ID. ARITHMETIC.
      *> Adds the value of two Java Integers, stores the result in a
      *> Java Integer, and displays the result. Note that the compiler
      *> will issue a "type clash" error if we try to directly use a
      *> java.lang.Integer (or even its intValue) in a COBOL arithmetic
      *> statement. Therefore we use the SET statement to cast data back
      *> and forth between the java.lang.Integer data type and a COBOL
      *> numeric usage.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS J-INTEGER AS "java.lang.Integer"
           .
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  JAVA-INT-1   OBJECT REFERENCE J-INTEGER.
       01  JAVA-INT-2   OBJECT REFERENCE J-INTEGER.
       01  JAVA-SUM     OBJECT REFERENCE J-INTEGER.
       01  COBOL-INT-1  PIC S9(9).
       01  COBOL-INT-2  PIC S9(9).
       01  COBOL-SUM    PIC S9(9).
       PROCEDURE DIVISION.
           SET JAVA-INT-1 TO J-INTEGER:>new(5)
           SET JAVA-INT-2 TO J-INTEGER:>new(10)

           SET COBOL-INT-1 TO JAVA-INT-1
           SET COBOL-INT-2 TO JAVA-INT-2

           ADD COBOL-INT-1 TO COBOL-INT-2 GIVING COBOL-SUM
           SET JAVA-SUM TO J-INTEGER:>new(COBOL-SUM)

           DISPLAY JAVA-INT-1 " + " JAVA-INT-2 " = " JAVA-SUM
           GOBACK.
